import router from '@/router';
import store from '@/store';
import { getToken } from '@/utils/auth';


router.beforeEach(async (to, from, next) => {
  // 判断路由是否需要登录
  if (to.meta.requireAuth) {
    if (getToken()) {
      next();
      return;
    } else {
      next({
        path: '/',
        query: {
          redirect: to.fullPath,
        }, // 将跳转的路由path作为参数，登录成功后跳转到该路由
      });
      return;
    }
  }

  next();
});

export default router;
